package com.dtyunxi.utils;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * 数据库工具类
 * <p/>
 * <br>==========================
 * <br> 公司：云徙科技
 * <br> 开发：wu.yingnan@dtyunxi.com
 * <br> 版本：1.0
 * <br> 创建时间：2017/4/11
 * <br>==========================
 */
public class DBUtil {

    private Connection connection;

    public DBUtil() {
        try {
            Class.forName(ResourceUtil.get("jdbc.driver"));
            this.connection = DriverManager.getConnection(ResourceUtil.get("jdbc.url"), ResourceUtil.get("jdbc.user"), ResourceUtil.get("jdbc.password"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public Connection getConnection() {
        return connection;
    }

    public void setConnection(Connection connection) {
        this.connection = connection;
    }

    public void close() {
        if (null != connection) {
            try {
                connection.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
